﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Tomahawk.Runtime.Resources
{
    /// <summary>
    /// This class manages the resource loading and readyness. 
    /// It will implement asynchronous assets loading
    /// </summary>
    public class ResourceManager
    {

        GraphicsDevice graphicsDevice;

        List<ILoadableResource> resources;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="graphicsDevice"></param>
        public ResourceManager(GraphicsDevice graphicsDevice)
        {
            this.graphicsDevice = graphicsDevice;
            this.resources = new List<ILoadableResource>();
        }

        /// <summary>
        /// Register a loadable resource
        /// </summary>
        internal void registerResource(ILoadableResource newResource)
        {
            resources.Add(newResource);
        }

        /// <summary>
        /// Load all the resources
        /// </summary>
        public void LoadPendantResources(ContentManager loader)
        {
            //load all objects
            foreach (ILoadableResource loadable in this.resources)
            {
                if (!loadable.IsReady) loadable.LoadContents(this.graphicsDevice, loader);
            }

            //clear the pendant resources list
            this.resources.Clear();
        }

    }

}
